package com.nju.bean.client.string;

import org.dom4j.*;

public class XmlMaker {
	
	static public String makeSimpleFeedback(String result){
		Document doc = DocumentHelper.createDocument();
		doc.setXMLEncoding("GB2312");
		Element root = doc.addElement(Configration.getIniKey("result"));
		root.setText(result);
		return doc.asXML()+"\n";
	}
	
	static public String makeSimpleText(String rootName,String text){
		Document doc = DocumentHelper.createDocument();
		doc.setXMLEncoding("GB2312");
		Element root = doc.addElement(rootName);
		root.setText(text);
		return doc.asXML()+"\n";
	}
	
	static public String makePost(String author,String text,double longitude ,double latitude,boolean pic){
		Document doc = DocumentHelper.createDocument();
		doc.setXMLEncoding("GB2312");
		Element root = doc.addElement("post");
		root.addAttribute("author", author);
		root.addAttribute("text",text);
		root.addAttribute("longitude", longitude+"" );
		root.addAttribute("latitude", latitude+"");
		root.addAttribute("pic", pic+"");
		return doc.asXML()+'\n';
	}
	static public String makeChoiceTittle(String id,String tittle){
		Document doc = DocumentHelper.createDocument();
		doc.setXMLEncoding("GB2312");
		Element root = doc.addElement("choicetittle");
		root.addAttribute("topicid", id);
		root.addAttribute("tittle", tittle);
		return doc.asXML()+'\n';
	}
	static public String makeReply(String newsId,String author,String reply){
		Document doc = DocumentHelper.createDocument();
		doc.setXMLEncoding("GB2312");
		Element root = doc.addElement("reply");
		root.addAttribute("topicid", newsId);
		root.addAttribute("author", author);
		root.addAttribute("reply", reply);
		return doc.asXML()+'\n';
	}
	static public String makeScoreToFragment(String fragmentId,String userId,int score){
		Document doc = DocumentHelper.createDocument();
		doc.setXMLEncoding("GB2312");
		Element root = doc.addElement("score");
		root.addAttribute("fragmentId", fragmentId);
		root.addAttribute("userId", userId);
		root.addAttribute("score", score+"");
		return doc.asXML()+"\n";
	}
	
	static public String makeUserInfo(String name,String secret,String token){
		Document doc = DocumentHelper.createDocument();
		doc.setXMLEncoding("GB2312");
		Element root = doc.addElement("userinfo");
		root.addAttribute("name", name);
		root.addAttribute("secret", secret);
		root.addAttribute("token", token+"");
		return doc.asXML()+"\n";
	}
	
	static public String makeTopicRequest(String type,double latitude,double longitude){
		Document doc = DocumentHelper.createDocument();
		doc.setXMLEncoding("GB2312");
		Element root = doc.addElement("requestTopic");
		root.addAttribute("type", type);
		root.addAttribute("latitude", latitude+"");
		root.addAttribute("longitude", longitude+"");
		return doc.asXML()+"\n";
	}
}